package com.nullpointer.xchat.utils;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.content.Context;

public class TextFilter {
	private static final Map<String, String> filters = new HashMap<String, String>();

	static {
		for (int i = 0; i < Common.badWord.length; i++) {
			filters.put(Common.badWord[i], Common.badWordReplace[i]);
		}
	}

	public static String getFilterText(Context context, String text) {
		//StringBuilder result = new StringBuilder();
		for (Entry<String, String> entry : filters.entrySet()) {
			Matcher matcher = Pattern.compile(Pattern.quote(entry.getKey()))
					.matcher(text);
			if (matcher.find()) {
				text = text.replaceAll(entry.getKey(), entry.getValue());
			}
		}
		return text;
	}
}
